package com.self.finance.service.impl;

import com.self.finance.model.Coin;
import com.self.finance.service.CoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.self.finance.model.CoinConfig;
import com.self.finance.mapper.CoinConfigMapper;
import com.self.finance.service.CoinConfigService;
import org.springframework.util.Assert;

@Service
public class CoinConfigServiceImpl extends ServiceImpl<CoinConfigMapper, CoinConfig> implements CoinConfigService{

    @Autowired
    private CoinService coinService;

    @Override
    public CoinConfig findByCoinId(Long coinId) {
        return getById(coinId);
    }

    @Override
    public boolean updateOrSave(CoinConfig coinConfig) {
        //查询币种
        Coin coin = coinService.getById(coinConfig.getId());
        Assert.notNull(coin,"币种不存在");
        coinConfig.setCoinType(coin.getType());
        coinConfig.setName(coin.getName());
        return saveOrUpdate(coinConfig);
    }
}
